using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using UnityEngine.U2D;
using Unity.VisualScripting;
using System.Linq;

namespace ProjectSurvivor
{
	
	public partial class UnlockiconPanel : UIElement,IController
	{
		private Dictionary<string, Sprite> mUnlockenKey = new Dictionary<string,Sprite>();
		ResLoader mResLoader = ResLoader.Allocate();

        public override string ComponentName => throw new NotImplementedException();
		List<Button> buttons = new List<Button>();
		private void Awake()
		{
			UnlockediconTemplate.Hide();
			var iconAtlas = mResLoader.LoadSync<SpriteAtlas>("Icon");
			
			
			Global.SimpleSwordCount.RegisterWithInitValue(self =>
			{
				buttons = this.GetSystem<ExpUpgrdeSystem>().TypeItems;
				
				Debug.Log(buttons.Count);
			
					if (Global.SimpleSwordUnlocked.Value && !mUnlockenKey.ContainsKey(Global.SimpleSwordUnlocked.ToString()))
					{
						UnlockediconTemplate.InstantiateWithParent(UnlockedkediconRoot)
						.Self(self =>
						{

							self.sprite = iconAtlas.GetSprite("bomb");
							mUnlockenKey.Add(Global.SimpleSwordUnlocked.ToString(), self.sprite);
						}).Show();

					}

					else if (Global.SimpleKnifeUnlocked.Value && !mUnlockenKey.ContainsKey(Global.SimpleKnifeUnlocked.ToString()))
					{

						UnlockediconTemplate.InstantiateWithParent(UnlockedkediconRoot)
						.Self(self =>
						{
							self.sprite = iconAtlas.GetSprite("simple_sword");
							mUnlockenKey.Add(Global.SimpleKnifeUnlocked.ToString(), self.sprite);
						}).Show();
					}
					else if (Global.RotateSwordUnlocked.Value && !mUnlockenKey.ContainsKey(Global.RotateSwordUnlocked.ToString()))
					{
						UnlockediconTemplate.InstantiateWithParent(UnlockedkediconRoot)
						.Self(self =>
						{

							self.sprite = iconAtlas.GetSprite("movement_icon");
							self.name = "bomb";
							mUnlockenKey.Add(Global.RotateSwordUnlocked.ToString(), self.sprite);
						}).Show();
					}
					else if (Global.noRotateSwordUnlocked.Value && !mUnlockenKey.ContainsKey(Global.noRotateSwordUnlocked.ToString()))
					{
						UnlockediconTemplate.InstantiateWithParent(UnlockedkediconRoot)
						.Self(self =>
						{

							self.sprite = iconAtlas.GetSprite("simple_sword");
							self.name = "bomb";

							mUnlockenKey.Add(Global.noRotateSwordUnlocked.ToString(), self.sprite);
						}).Show();
					}
					else if (Global.BasketBallUnlocked.Value && !mUnlockenKey.ContainsKey(Global.BasketBallUnlocked.ToString()))
					{
						UnlockediconTemplate.InstantiateWithParent(UnlockedkediconRoot)
						.Self(self =>
						{

							self.sprite = iconAtlas.GetSprite("fly_icon");
							self.name = "bomb";
							mUnlockenKey.Add(Global.BasketBallUnlocked.ToString(), self.sprite);
						}).Show();
					}



				
			}
			).UnRegisterWhenGameObjectDestroyed(gameObject);
			
		}

		protected override void OnBeforeDestroy()
		{
			mResLoader.Recycle2Cache();
			mResLoader = null;
		}

        public IArchitecture GetArchitecture()
        {
			return Global.Interface;
        }
    }
}
